
#ifndef __I_LEARNOPENGL_COUNTED_H_INCLUDED__
#define __I_LEARNOPENGL_COUNTED_H_INCLUDED__
#include "LDXConfig.h"

namespace ldx
{

	//! Base class of most objects of the Irrlicht Engine.
	class IReferenceCounted
	{
	public:
		IReferenceCounted()
			:DebugName(0), ReferenceCounter(1)
		{

		}

		//! Destructor.
		virtual ~IReferenceCounted()
		{

		}

		//! Grabs the object. Increments the reference counter by one.
		void grab()
		{
			++ReferenceCounter;
		}

		//! Drops the object. Decrements the reference counter by one.
		bool drop() 
		{
			// someone is doing bad reference counting.
			if (ReferenceCounter < 0)
			{
				throw::std::runtime_error("drop:ReferenceCounter<0" + std::string(DebugName));
			}
			--ReferenceCounter;
			if (!ReferenceCounter)
			{
				delete this;
				return true;
			}

			return false;
		}

		int getReferenceCount() 
		{
			return ReferenceCounter;
		}

		const char* getDebugName() 
		{
			return DebugName;
		}

	protected:


		void setDebugName(const char* newName)
		{
			DebugName = newName;
		}


	private:
		const char* DebugName;
		int ReferenceCounter;
	
	};

} // end namespace lg

#endif

